package com.shiminghui;

import java.util.ArrayList;
import java.util.Scanner;

public class Test5 {

    public static void main(String[] args) {

        ArrayList<User> arrayList = new ArrayList<>();

        Scanner scanner = new Scanner(System.in);

        User user = new User("1","zxc","123456");
        User user1 = new User("2","zxc","123456");
        User user2 = new User("3","zxc","123456");

        arrayList.add(user);
        arrayList.add(user1);
        arrayList.add(user2);

        System.out.println("输入要查询的Id");
        User user3= query(scanner.next(),arrayList);
        if (user3!=null){
            System.out.println(user3);
        }else {
            System.out.println("没涨到");
        }

    }

    public static User query(String id,ArrayList<User> list){
        for (int i = 0; i < list.size(); i++) {
            if (id.equals(list.get(i).getId())){
                return list.get(i);
            }
        }
        return null;
    }
}
